package structures;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Pattern;

public class Q {

    String name;

    static Q[] all() {
        return new Q[100];
    }

    static Q byName(String name) {
        return new Q();
    }

    public void save(M m) {

    }

}

class M {

}

abstract class Binding {
    protected final String bindingKey;

    Binding(String bindingKey) {

        this.bindingKey = bindingKey;
    }

    abstract Q[] match(String routingKey);

}


class Fanout extends Binding {

    Fanout() {
        super(null);
    }

    @Override
    Q[] match(String routingKey) {
        return new Q[0];
    }
}

class Direct extends Binding {


    Map<String, Q[]> map;

    Direct() {
        super(null);

    }

    @Override
    Q[] match(String routingKey) {
        return map.get(routingKey);
    }
}

class Topic extends Binding {
    Map<String, Q> map;

    Topic(String bindingKey) {
        super(bindingKey);

    }

    @Override
    Q[] match(String routingKey) {
        List<Q> qList = new ArrayList<>();

        return qList.toArray(new Q[0]);
    }


    private boolean matchTopic(String topic) {
        return true;
    }
}

class X {
    Binding binding = new Fanout();


    public void publish(M m, String routingKey) {
        Q[] match = binding.match(routingKey);
        for (Q q : match) {
            q.save(m);
        }
    }
}